﻿using MongoDB.Bson;

namespace Dark_Core_Server.Models.Message
{
    public static class MsgHelper
    {
        /// <summary>
        /// 转换为SimpleMsgRecord(简单消息记录)
        /// </summary>
        /// <param name="document">消息文档</param>
        /// <returns></returns>
        public static SimpleMsgRecord ToSimpleMsgRecord(this MsgDocument document) => new SimpleMsgRecord(document.Tag, document.Title,
            document.Content, document.Attachments, document.Version,
            document.RecipientLevel);

        /// <summary>
        /// 根据记录创建文档
        /// </summary>
        /// <param name="record">记录</param>
        /// <param name="publisherId">发布者ID</param>
        /// <returns></returns>
        public static MsgDocument CreateDocument(this SimpleMsgRecord record,ObjectId publisherId) => new MsgDocument() { PublisherId = publisherId,Title = record.Title,Tag = record.Tag,Content = record.Content,Attachments = record.Attachments,Version = record.Version,RecipientLevel = record.RecipientLevel};

        /// <summary>
        /// 转换为MsgQueryMode
        /// </summary>
        /// <param name="mode">查询字符串</param>
        /// <returns></returns>
        public static MsgQueryMode ToMsgQueryMode(this string mode)
        {
            var result = mode.ToUpper() switch
            {
                "ALL" => MsgQueryMode.All,
                "TAG" => MsgQueryMode.Tag,
                "TITLE" => MsgQueryMode.Title,
                _ => MsgQueryMode.All
            };
            return result;
        }

    }
}
